<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<!DOCTYPE html>
<html lang="zh-CN" >
<head>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>挂靠公司账户列表</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>

<script type="text/javascript">
	var grid = null;
	var _compId;
	var lxxz = '${lxxz}';
	var proIntId = '${proIntId}';

	$(function () {
		_compId = '${compId}';
		var _url = '<%=path%>/project/prjLnkCompBkAcc/initList.do?compId=' + _compId ;
	    $("#ligergrid1").ligerGrid({
	    	url: _url,
	    	method : 'get',
	        columns: [
	            { display: '收款方', align:'left',name:'rcptUnt', width: 120 },
	            { display: '收款账号',align:'left', name: 'accNo', width: 120,
	            	render: function (rowdata, rowindex, value){
	            		var h='<a href="javascript:showDetail(';
	            		h+="'"+rowdata.id+"'";
	                    h+=')">'+rowdata.accNo+'</a>';
	                	return h;
	            	}
	            },
	            { display: '开户行',align:'left', name: 'bkNm', width: 120 },
	            { display: '开户行行号',align:'left', name: 'bkNo', width: 120 },
	            { display: '区域',align:'left', name: 'rgnNms', width: 120 ,
	            	render: function (rowdata, rowindex, value){
	            		var h= '<span class="gridTip" title="' + value +'">'+ value +'</span>'
	            		     return h;
	            		}
				},
	            { display: '账号类型', name: 'bizTypCdNm', width: 80},
	            { display: '账号用途', name: 'purpCdNm', width: 120},
	            { display: '评审状态', name: 'audStsCdNm', width: 80 },
	            { display: '流程编号', width: 180,
	            	render: function (rowdata, rowindex, value){
	            		var h= "";
	            		if(StringUtils.isNotEmpty(rowdata.pno)){
	            			if(rowdata.pno.indexOf("账号")>-1){
			            		h='<a href="javascript:showFlow(';
	            			}else{
			            		h='<a href="javascript:showSplFlow(';
	            			}
		            		h+="'"+rowdata.pinstId+"'";
		            		h+=",'"+rowdata.audStsCd+"'";
		            		h+=",'"+rowdata.id+"'";
		                    h+=')">'+rowdata.pno+'</a>';
	            		}
	                	return h;
	            	}
	            },
	            { display: '提报人', name: 'crtUsrNm', width: 100 },
	            getOperateColumn()
	        ],
	        pageSize:10,
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        height:'100%',
	        heightDiff:-2,
	        rownumbers:true,
	    });
	    grid = liger.get("ligergrid1");
	    grid.setHeight(100);
	    $("#searchBar").ligerForm();

	    $("#searchBtn").click(function(event) {
	         var form = new liger.get("searchBar");
	         var data = form.getData();
	         for (name in data){
	            grid.setParm(name,data[name]);
	         };
	        grid.reload();
	    });
	    $("#clearBtn").click(function(event) {
	        $("#resetBtn").click();  //重置 input-text
	        var form = liger.get("searchBar");
	        form.setData({  //重置select等特殊表单
	            "brCd": " ",
	            "audStsCd": " "
	        });
	    });
	});
	//显示流程
    function showFlow(_pInstId,_audStsCd,_businessKey){
    	if(StringUtils.isEmpty(_pInstId)){
    		UIUtils.alertWarning(CommonConstant.C_P_INSTANCEID_NOT_HERE);
    		return;
    	}
    	var _formUrl = "/project/prjLnkCompBkAcc/toDetail.do?isFlow=1@@id=";
    	var params = "?pInsId="+_pInstId+"&status="+_audStsCd+"&businessKey="+_businessKey+"&formUrl="+_formUrl;
    	Add_navTab('tab_spl_bank_flow_'+_pInstId,'查看流程',"<%=path%>/flow/flow/toFlowShowPageFowBus.do"+params);
    }
    function showSplFlow(_pInstId,_audStsCd,_businessKey){
    	if(StringUtils.isEmpty(_pInstId)){
			UIUtils.alertWarning(CommonConstant.C_P_INSTANCEID_NOT_HERE);
			return;
		}
		var _formUrl = "/project/prjlnkcomp/toDetailPage.do?isFlow=1@@id=";
		var params = "?pInsId="+_pInstId+"&status="+_audStsCd+"&businessKey="+_compId+"&formUrl="+_formUrl;
		Add_navTab('tab_spl_flow_'+_pInstId,'查看流程',"<%=path%>/flow/flow/toFlowShowPageFowBus.do"+params);
    }

	function getOperateColumn(){
		return {
        	display: '操作',width:250,align:'left',
        	render: function (rowdata, rowindex, value){
        		/* var h;
        		if(rowdata.audStsCd==CommonConstant.C_AUD_NO_HAPPEN_CODE||rowdata.audStsCd==CommonConstant.C_AUD_NO_PASS_CODE){
        			var h='<a class="sq-button-hasicon" href="javascript:startFlow(';
	                h+="'"+rowdata.id+"'";
	                h+=",'ligergrid_bankacc'"
	                h+=')"><i class="sqBtnIco_47"></i>发起审核流程</a>'
        		}else if(rowdata.audStsCd==CommonConstant.C_AUD_PASS_CODE){
        			var h='<a class="sq-button-hasicon" href="javascript:modifyFlow(';
	                h+="'"+rowdata.id+"'";
	                h+=",'ligergrid_bankacc'"
	                h+=')"><i class="sqBtnIco_47"></i>发起变更流程</a>'
        		}
	            return h; */
        		var h='<a class="sq-button-hasicon" href="javascript:startFlow(';
	                h+="'"+rowdata.id+"'";
	                h+=')"><i class="sqBtnIco_6"></i>发起审核流程</a>';
	    		var g='<a class="sq-button-hasicon" href="javascript:change(';
	        		g+="'"+rowdata.id+"'";
	                g+=')"><i class="sqBtnIco_4"></i>修改</a>';
                var u='<a class="sq-button-hasicon" href="javascript:changePurpCd(';
                    u+="'"+rowdata.id+"'";
                    u+=')"><i class="sqBtnIco_4"></i>修改账户用途</a>';
	        	var d='<a class="sq-button-hasicon" href="javascript:deleteRecord(';
	        		d+="'"+rowdata.id+"'";
	                d+=')"><i class="sqBtnIco_7"></i>删除</a>';
	            //var b="";
	            /*if(rowdata.bdState == "0"){
	            	b+='<a class="sq-button-hasicon" href="javascript:bdBankAcc(';
	            	b+="'"+rowdata.accNo+"'";
	            	b+=",'"+rowdata.rgnPrCd+"'";
	            	b+=",'"+rowdata.rgnCyCd+"'";
	                b+=')"><i class="sqBtnIco_6"></i>绑定银行卡</a>';
	            }else{
	            	b+='<a class="sq-button-hasicon" href="javascript:jbBankAcc(';
	            	b+="'"+rowdata.accNo+"'";
	                b+=')"><i class="sqBtnIco_6"></i>解除绑定</a>';
	            }*/
	            //如果账号流程实例ID和供应商流程实例ID相同  则允许修改
	            if(StringUtils.isNotEmpty(rowdata.pinstId) && StringUtils.isNotEmpty(proIntId) && rowdata.pinstId==proIntId){
	            	return g;
	            }
                //审核中 审核通过 不能再次发起流程 木有修改和删除
                if(rowdata.audStsCd == FlowConstant.FLOW_CHECK_STATE_IN || rowdata.audStsCd == FlowConstant.FLOW_CHECK_STATE_PASS
                    || rowdata.audStsCd == FlowConstant.FLOW_CHECK_STATE_RETURN_BACK){
                    return u;
                }
	            //审核通过 不能再次发起流程 木有修改和删除 绑定银行卡
	            /*if(rowdata.audStsCd == FlowConstant.FLOW_CHECK_STATE_PASS){
	            	return b;
	            }*/
	            //审核中 不能再次发起流程 木有修改和删除 木有绑定银行卡
	            /*f(rowdata.audStsCd == FlowConstant.FLOW_CHECK_STATE_IN || rowdata.audStsCd == FlowConstant.FLOW_CHECK_STATE_RETURN_BACK){
	            	return ;
	            }*/
	            return h+g+d;
        	}
		};
	}
	var ligerBankAccForm;
	function bdBankAcc(accNo,rgnPrCd,rgnCyCd){
		var bankName = "";
		var fstOrg = "";
		var cardType = "";
		$.ligerDialog.SQopen({
            width: 600,
            top: 100,
            buttons: [
                {
                    text: "确定", cls: 'l-dialog-btn-ok', onclick:function(){
                    	confirmBankAcc(accNo,bankName,fstOrg,cardType);
                    }
                }, {
                    text: "取消", cls: 'l-dialog-btn-no', onclick:function(){
                    	$.ligerDialog.hide();
                    }
                }
            ],
            title : '绑定银行卡',
            target: $("#div_bankAcc_confirm")
        });

		ligerBankAccForm = $("#div_bankAcc_confirm_form").ligerForm({
         	 validate: true
  		});
		//清空字段值
		resetBankAccForm(ligerBankAccForm);

		$.ajax({
			type: 'post',
			dataType:'json',
			data:{cardNo:accNo},
			url: '<%=path%>/system/sysEmpBankAcc/queryBankBin.do',
			success:function(msg){
				if(msg.success == 1){
					/* alert(JSON.stringify(msg));
					return; */
					bankName = msg.data.bankName;
					fstOrg = msg.data.bankCode;
					cardType = msg.data.cardType;
					var dataList = msg.data.secOrg;
					var dataArr = [];
					if(dataList!=null ||dataList!=""){
						for(var i=0;i<dataList.length;i++){
							var kv = {};
							kv.key = dataList[i];
							kv.value = dataList[i];
							kv.isHide = false;
							dataArr.push(kv);
						}
					}
					liger.get('rgnProvCd').setData(dataArr);
					liger.get('rgnProvCd').updateStyle();
					getCity(fstOrg);
				}else{
					 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
				}

			}
		});
	}


	function getCity(fstOrg){
		$("#rgnProvCd").change(function(event) {
			var secOrg = $("#rgnProvCd").val();
	       if(secOrg!=""){
	    	   $.ajax({
	   			type: 'post',
	   			dataType:'json',
	   			data:{fstOrg:fstOrg,
	   				  secOrg:secOrg
	   			},
	   			url: '<%=path%>/system/sysEmpBankAcc/queryThdOrg.do',
	   			success:function(msg){
	   				if(msg.success == 1){
	   					var dataList = msg.data;
	   					var dataArr = [];
	   					if(dataList!=null ||dataList!=""){
	   						for(var i=0;i<dataList.length;i++){
	   							var kv = {};
	   							kv.key = dataList[i];
	   							kv.value = dataList[i];
	   							kv.isHide = false;
	   							dataArr.push(kv);
	   						}
	   					}
	   					liger.get('rgnCityCd').setData(dataArr);
	   					liger.get('rgnCityCd').updateStyle();
	   				}else{
	   					 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
	   				}

	   			}
	   		});
	       }
	    });
	}

	//重置表单
	function resetBankAccForm(ligerBankAccForm){
		//清理数据
		$("#cstMgrNm").val("");
		$("#cstMgrCertNo").val("");
		$("#telNo").val("");
	}

	function confirmBankAcc(accNo,bankName,fstOrg,cardType){
		var rgnPrCd = $("#rgnProvCd").val();
		var rgnCyCd = $("#rgnCityCd").val();
		if (!ligerBankAccForm.valid()||rgnPrCd==""||rgnCyCd=="") {
            UIUtils.alertWarning(LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO);
            return false; //验证不通过，不执行以下代码
        }
		var cstMgrNm = $("#cstMgrNm").val();
		var cstMgrCertNo = $("#cstMgrCertNo").val();
		var telNo = $("#telNo").val();
					$.ajax({
						type: 'post',
						dataType:'json',
						data:{
							payAcntCode:accNo,
							secOrg:rgnPrCd,
							thdOrg:rgnCyCd,
							payAcntName:cstMgrNm,
							certNo:cstMgrCertNo,
							cardTel:telNo,
							bankName:bankName,
							cardType:cardType,
							fstOrg:fstOrg
						},
						url: '<%=path%>/system/sysEmpBankAcc/signedBank.do',
						success:function(msge){
							 if(msge.success == 1){
								 $.ligerDialog.SQalert({content:msge.info, SQ_type: "success"});
								 $.ligerDialog.hide();
								 grid.reload();
							 }else{
								 $.ligerDialog.SQalert({content:msge.info, SQ_type: "error"});
							 }
						}
					});

	}

	function jbBankAcc(accNo){
		$.ajax({
			type: 'post',
			dataType:'json',
			data:{
				accNo:accNo
			},
			url: '<%=path%>/system/sysEmpBankAcc/jbEmpBankAcc.do',
			success:function(msge){
				 if(msge.success == 1){
					 $.ligerDialog.SQalert({content:msge.info, SQ_type: "success"});
					 grid.reload();
				 }else{
					 $.ligerDialog.SQalert({content:msge.info, SQ_type: "error"});
				 }
			}
		});
	}

	var callback = function () {
		grid.reload();
    };
	//新增数据
	function add(){
        $.ligerDialog.SQopen({
            width: 900,
            height:400,
            title : '新增挂靠公司账户',
            url:'<%=path%>/project/prjLnkCompBkAcc/toAddPage.do?compId='+_compId,
            buttons: [{
	                text: "保存", type: 'ok', cls: 'l-dialog-btn-ok',
	                onclick: function (item, Dialog) {
	                    //在子页面里绑定 frameElement.dialog.onOk = function () {}
	                    if (Dialog.onOk) Dialog.onOk();
	                }
	            }, {
	                text: "取消", type: 'cancel', cls: 'l-dialog-btn-no',
	                onclick: function (item, Dialog) {
	                    //在子页面里绑定 frameElement.dialog.onCancel = function () {}
	                    if (Dialog.onCancel) Dialog.onCancel();
	                }
	            }
	        ]
        });
	}
	 //修改数据
	function change(_id){
		 if(!_id)return;
		$.ligerDialog.SQopen({
            width: 900,
            height:400,
            title : '修改挂靠公司账户信息',
            url:'<%=path%>/project/prjLnkCompBkAcc/toAddPage.do?id='+_id+'&compId='+_compId,
            buttons: [{
	                text: "保存", type: 'ok', cls: 'l-dialog-btn-ok',
	                onclick: function (item, Dialog) {
	                    //在子页面里绑定 frameElement.dialog.onOk = function () {}
	                    if (Dialog.onOk) Dialog.onOk();
	                }
	            }, {
	                text: "取消", type: 'cancel', cls: 'l-dialog-btn-no',
	                onclick: function (item, Dialog) {
	                    //在子页面里绑定 frameElement.dialog.onCancel = function () {}
	                    if (Dialog.onCancel) Dialog.onCancel();
	                }
	            }
	        ]
        });
	}
	function changePurpCd(_id){
		 if(!_id)return;
		$.ligerDialog.SQopen({
            width: 900,
            height:400,
            title : '修改挂靠公司账户信息',
            url:'<%=path%>/project/prjLnkCompBkAcc/toAddPage.do?disable=1&id='+_id+'&compId='+_compId,
            buttons: [{
	                text: "保存", type: 'ok', cls: 'l-dialog-btn-ok',
	                onclick: function (item, Dialog) {
	                    //在子页面里绑定 frameElement.dialog.onOk = function () {}
	                    if (Dialog.onOk) Dialog.onOk();
	                }
	            }, {
	                text: "取消", type: 'cancel', cls: 'l-dialog-btn-no',
                    onclick: function (item, Dialog) {
	                    //在子页面里绑定 frameElement.dialog.onCancel = function () {}
	                    if (Dialog.onCancel) Dialog.onCancel();
	                }
	            }
	        ]
        });
	}
	//详情
	function showDetail(_id){
		if(!_id)return;
		$.ligerDialog.SQopen({
            width: 900,
            height:400,
            title : '挂靠公司账号详情',
            url:'<%=path%>/project/prjLnkCompBkAcc/toDetail.do?id='+_id,
            buttons: [{
	                text: "关闭", type: 'cancel', cls: 'l-dialog-btn-no',
	                onclick: function (item, Dialog) {
	                    //在子页面里绑定 frameElement.dialog.onCancel = function () {}
	                    if (Dialog.onCancel) Dialog.onCancel();
	                }
	            }
	        ]
        });
	}
	//删除数据
	function deleteRecord(_id){
		if(!_id)return;
		var _ids = [];
		_ids.push(_id);
		$.ligerDialog.confirm(LogUtils.LOG_CMM_DELETE_CONFIRM, function (flag) {
			if(flag == false)return;
			var wait_dialog;
			$.ajax({
				type: 'post',
				dataType:'json',
				data:{ids:JSON.stringify(_ids)},
				url: '<%=path%>/project/prjLnkCompBkAcc/removeByIds.do',
				beforeSend: function(){
			          wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
			     },
				success:function(msg){
					wait_dialog.close();
					 if(msg.success == 1){
						 $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
						 grid.reload();
					 }else{
						 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
					 }
				}
			});
		});
	}
	//发起审核流程
	function startFlow(_id){
		if(!_id)return;
		//发起流程确认  2017-6-8 by YAOXIURONG
        $.ligerDialog.confirm(FlowConstant.FLOW_ADD_START_CONFIRM, function (flag) {
			if(flag == false)return;
			const modelTyp = "080";//流程业务分类-挂靠公司账号审核
			if(StringUtils.isEmpty(modelTyp)){
				console.log("modelTyp is null");
				return;
			}
	        var flowDialog = $.ligerDialog.SQopen({
                url: '<%=path%>/flow/flow/toForStartListPage.do?modelTyp=' + modelTyp,
                width: 700,
                height: 400,
                title: '请选择要发起的流程',
                buttons: [{
                    text: "确定", type: 'ok', cls: 'l-dialog-btn-ok',
                    onclick: function (item, Dialog) {
                        if (Dialog.onOk) Dialog.onOk();
                    }
                }, {
                    text: "取消", type: 'cancel', cls: 'l-dialog-btn-no',
                    onclick: function (item, Dialog) {
                        if (Dialog.onCancel) Dialog.onCancel();
                    }
                }],
                onClose: function () {
                    var json = flowDialog._DATA;
                    console.log(json);
                    if (!json) {
                        return;
                    }
                    var wait_dialog = $.ligerDialog.SQalert({
                        content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting", onClose: function () {
                        }
                    });
                    $.ajax({
                        type: 'post',
                        dataType: 'json',
                        data: {
                            id: _id,
                            procDefKey: json.procDefKey,
                            procDefId: json.procDefId,
                            procNo: json.procNo
                        },
                        url: '<%=path%>/project/prjLnkCompBkAcc/addFlowStart.do',
                        success: function (msg) {
                            wait_dialog.close();
                            if (msg.success === 1) {
                                UIUtils.alertSuccessHold1(msg.info);
                                if (lxxz === "true") {
                                    Remove_navTab();
                                    return;
                                }
                                grid.reload();
                            } else {
                                UIUtils.alertErrorHold1(msg.info);
                            }
                        }
                    });
                }
	        });
        });
	}
	function iframeResize () {
	    if (parent.mainApp) {
	        parent.mainApp.parentTab.onResize();
	    };
	}

</script>

<body class="iframeBody">
<div class="Wrapper">
<div class="searchArea">
    <form id="searchBar">
        <div class="fieldset1 clearFix">
            <div class="clearFix"></div>
            <div class="btnsBox formBtns notRight">
            	<c:if test="${allowMdfBank!=1 }">
	                <span id="addBtn" class="sq-button-round" onclick="add();">新增</span>
            	</c:if>
                <!-- <span id="changeBtn" class="sq-button-round" onclick="change();"><i class="sqBtnIco_4"></i>修改</span>
                <span id="detailBtn" class="sq-button-round" onclick="showDetail();"><i class="sqBtnIco_2"></i>详情</span>
                <span id="delBtn" class="sq-button sq-button-hasicon" onclick="deleteRecord();"><i class="sqBtnIco_7"></i>删除</span> -->
            </div>
        </div>
    </form>
</div>
<div id="ligergrid1" class="sq-grid"></div>

<div id="div_bankAcc_confirm" style="display:none">
	<form id="div_bankAcc_confirm_form">
            <div class="fieldset1 tabel_col tabel_col_s clearFix noBorder">
            	<div class="fieldBox col_100">
					<div class="label" id="div_cstMgrNm_tip">姓名</div>
						<div class="field">
							<input name="cstMgrNm" id="cstMgrNm" type="text" class="ui-textbox" value="" validate="{required:true,maxlength:30}">
	                    <span class="requiredSymbol">*</span>
						</div>
				</div>
				<div class="fieldBox col_100">
					<div class="label" id="div_cstMgrCertNo_tip">身份证号</div>
						<div class="field">
							<input name="cstMgrCertNo" id="cstMgrCertNo" type="text" class="ui-textbox" value="" validate="{required:true}">
	                    <span class="requiredSymbol">*</span>
						</div>
				</div>
				<div class="fieldBox col_100">
					<div class="label" id="div_telNo_tip">手机号</div>
						<div class="field">
							<input name="telNo" id="telNo" type="text" class="ui-textbox" value="">
						</div>
				</div>
				<div class="fieldBox col_100_auto">
                 <div class="label">区域</div>
                 <div class="field">
                 	<jsp:include page="../../system/sysRegion/region.jsp" flush="true" >
						<jsp:param name="regionShowLvl" value="2"/>
					</jsp:include>
					<span class="requiredSymbol">*</span>
                 </div>
			</div>
            </div>
    </form>
</div>
</body>
</html>
